package com.ddwl.user.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.MySqlUtil;
import com.ddwl.schema.bo.user.ProfitApplyQueryBo;
import com.ddwl.user.dao.mapper.ProfitApplyMapper;
import com.ddwl.user.dao.model.ProfitApply;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 类ProfitApplyDao.java的实现描述：DAO
 *
 * @author zach
 * @Date :2020-06-23 10:48.
 */
@Repository
public class ProfitApplyDao extends TkDao<ProfitApplyMapper, ProfitApply> {

    /**
     * 查询用户的审批数据
     * @param userId
     * @return
     */
    public ProfitApply queryUserApply(String userId){
        ProfitApply profitApply = new ProfitApply();
        profitApply.setUserId(userId);
        return selectOne(profitApply);
    }

    public ProfitApply queryUserApplyByIdCard(String idCard){
        ProfitApply profitApply = new ProfitApply();
        profitApply.setIdCard(idCard);
        return selectOne(profitApply);
    }

    public ProfitApply queryUserApplyByPhone(String phone){
        ProfitApply profitApply = new ProfitApply();
        profitApply.setPhone(phone);
        return selectOne(profitApply);
    }

    /**
     * 查询审批通过的用户
     * @return
     */
    public List<ProfitApply> queryApply(){
        ProfitApply profitApply = new ProfitApply();
        return select(profitApply);
    }


    public List<ProfitApply> queryApplyList(ProfitApplyQueryBo queryBo){
        Example example = getExample();
        example.and().andEqualTo("userId",queryBo.getUserId())
                .andEqualTo("regionId",queryBo.getRegionId())
                .andEqualTo("status", queryBo.getStatus())
                .andLike("idName", MySqlUtil.rightLike(queryBo.getIdName()))
                .andLike("idCard", MySqlUtil.rightLike(queryBo.getIdCard()))
                .andLike("phone", MySqlUtil.rightLike(queryBo.getPhone()))
                .andGreaterThanOrEqualTo("gmtCreated", queryBo.getStartTime())
                .andLessThan("gmtCreated", queryBo.getEndTime());
        return baseMapper.selectByExample(example);
    }

    public Integer queryApplyCount(ProfitApplyQueryBo queryBo){
        return baseMapper.queryApplyCount(queryBo);
    }
}
